﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using Frame.Lib.Core.Config;
using System.Runtime.Serialization.Formatters.Binary;

namespace Frame.Lib.Utilities
{
      public sealed class Serialize
    {
        private Serialize()
        {
        }

        public static string BinarySerialize(object info)
        {
            IFormatter formatter = new BinaryFormatter();
            //SysConfigBO config = new SysConfigBO();
            //SysConfigInfo cfgInfo = new SysConfigInfo();
            using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
            {
                formatter.Serialize(stream, info);

                byte[] buffer = stream.ToArray();

                return Convert.ToBase64String(buffer);
            }
        }

        public static object BinaryDeserialize(string base64String)
        {
            byte[] buffer = Convert.FromBase64String(base64String);
            using (System.IO.MemoryStream stream = new System.IO.MemoryStream(buffer))
            {

                IFormatter formatter = new BinaryFormatter();
                object info = formatter.Deserialize(stream);
                return info;
            }
        }
    }
}
